#include "WareSprite.h"

NS_CC_ENGINE_BEGIN

CWareSprite::CWareSprite(void)
{
}

CWareSprite::~CWareSprite(void)
{
}
//-------------------------------------------------------------------------
/** Creates an sprite with an image filename.
The rect used will be the size of the image.
The offset will be (0,0).
*/
CWareSprite* CWareSprite::create(const char *pszFileName)
{
	CWareSprite *pobSprite = new CWareSprite();
	if (pobSprite && pobSprite->initWithFile(pszFileName))
	{
		pobSprite->autorelease();
		return pobSprite;
	}
	CC_SAFE_DELETE(pobSprite);
	return NULL;
}
//-------------------------------------------------------------------------
/** Creates an sprite with an image filename and a rect.
The offset will be (0,0).
*/
CWareSprite* CWareSprite::create(const char *pszFileName, const CCRect& rect)
{
	CWareSprite *pobSprite = new CWareSprite();
	if (pobSprite && pobSprite->initWithFile(pszFileName, rect))
	{
		pobSprite->autorelease();
		return pobSprite;
	}
	CC_SAFE_DELETE(pobSprite);
	return NULL;
}
//-------------------------------------------------------------------------
/** Initializes an sprite with a texture and a rect in points, optionally rotated.
The offset will be (0,0).
IMPORTANT: This is the designated initializer.
*/
bool CWareSprite::initWithTexture(CCTexture2D *pTexture, const CCRect& rect)
{
	return CCSprite::initWithTexture( pTexture, rect );
	//do{
	//	CC_BREAK_IF(!CCSprite::initWithTexture(pTexture, rect));

	//	GLchar* pszFragSource =
	//		"#ifdef GL_ES \n \
	//		precision mediump float; \n \
	//		#endif \n \
	//		uniform sampler2D u_texture; \n \
	//		varying vec2 v_texCoord; \n \
	//		varying vec4 v_fragmentColor; \n \
	//		void main(void) \n \
	//		{ \n \
	//		// Convert to greyscale using NTSC weightings \n \
	//		float grey = dot(texture2D(u_texture, v_texCoord).rgb, vec3(0.299, 0.587, 0.114)); \n \
	//		gl_FragColor = vec4(grey, grey, grey, 1.0); \n \
	//		}";

	//	CCGLProgram* pProgram = new CCGLProgram();
	//	pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, pszFragSource);
	//	setShaderProgram(pProgram);
	//	pProgram->release();
	//	CHECK_GL_ERROR_DEBUG();

	//	this->getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
	//	this->getShaderProgram()->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
	//	this->getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
	//	CHECK_GL_ERROR_DEBUG();

	//	this->getShaderProgram()->link();
	//	CHECK_GL_ERROR_DEBUG();

	//	this->getShaderProgram()->updateUniforms();
	//	CHECK_GL_ERROR_DEBUG();

	//	return true;
	//} while (0);
	//return false;	
}

NS_CC_ENGINE_END